package Java2Test.mythread.threadtest3;

public class MyRunnable implements Runnable {
    static int number = 0;

    @Override
    public void run() {
        while (true) {
            synchronized (MyRunnable.class) {
                if (number > 100) {
                    break;//输出数字已到100
                } else {
                    if (number % 2 == 1){
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        //输出奇数
                        System.out.println(Thread.currentThread().getName() + number);
                    }
                    number++;

                }
            }
        }
    }
}
